import java.math.BigDecimal;

public class SpendSavePromotionStrategy implements PromotionStrategy {
    private BigDecimal total;
    private int spend;
    private int save;

    public SpendSavePromotionStrategy(BigDecimal total, int spend, int save) {
        this.total = total;
        this.spend = spend;
        this.save = save;
    }

    @Override
    public BigDecimal computeDiscountPrice() {
        int i = 1;
        while (this.total.compareTo(new BigDecimal(this.spend * i)) >= 0) {
            this.total = this.total.subtract(new BigDecimal(this.save));
            i++;
        }
        return this.total;
    }
}
